﻿using System;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GanagroLiteData;
using GeneralUtilities;
using System.Globalization;

namespace GanagroLiteBO
{
    public class PresenterReportes
    {
         IreporteView _irv;
         PresenterSummaryData pSummary;
        public PresenterReportes(IreporteView irv)
        {
            _irv = irv;
            pSummary = new PresenterSummaryData(_irv);
        }

        private PresenterReportes()
        { }

        public async Task<List<RepGananciaVida>> GetGananciaVida(ReportArgs rArgs)
        {
            string strSql = string.Format("SELECT Codigo,FechaInicial, PesoInicial, FechaFinal, Pesofinal, GananciaDia FROM RepGananciaVida");
            string whereClause = WhereClauseBuilder.BuildWhereClause(rArgs);
            await Task.Run(() =>  pSummary.SummaryGananciaVida(rArgs));

    
            using (GlContext gContext = new GlContext())
            {
                var result = await gContext.RepGananciaVidas.SqlQuery(string.Format("{0} {1}", strSql, whereClause)).ToListAsync();
                return result;
            }
        }

        public async Task<List<VentasVsCompra>> GetVentasVsCompras(ReportArgs rArgs)
        {
            string strSql = string.Format("SELECT Codigo,fecha_venta, peso_venta,Precio_kilo," +
                                               "Fecha_compra, Kilos_compra,Costo_kilo, " +
                                               "GananciaDiariaPesos,GananciaDiariaGramos " +
                                               " FROM VentasVsCompras ");
            string whereClause = WhereClauseBuilder.BuildWhereClause(rArgs);
            await Task.Run(() => pSummary.VentasVsCompras(rArgs));


            using (GlContext gContext = new GlContext())
            {
                var result = await gContext.VentasVsCompras.SqlQuery(string.Format("{0} {1}", strSql, whereClause)).ToListAsync();
                return result;
            }
        }

    }
}
